const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const root = path.resolve(__dirname);

module.exports = {
    entry: {
        index: path.join(root, './src/index.js')
    },
    output: {
        path: path.resolve(__dirname),
        filename: 'dist/[name]__[hash:8].js'
    },
    module: {
        loaders: [
            {
                test: /.vue$/,
                loader: 'vue-loader'
            },
            {
                test: /.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015'],
                    plugins: ["transform-runtime"]
                }
            },
            {
                test: /.(gif|png|jpg)$/,
                loader: 'url-loader',
                query: {
                    limit: 8192,
                    name: '[name].[ext]?[hash:8]'
                }
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.vue']
    },
    plugins: [
        // new CleanWebpackPlugin(['dist']),
        new HtmlWebpackPlugin({
            filename: path.join(root, 'index.html'),
            template: path.join(root, 'index.tpl'),
            inject: 'body'
        })
    ]
};